<?php
////////////////////////////////////////////////////////////////////////////////
@session_start();
require_once("includes/config.php");
include  $rootPath."includes/global.php";

include $rootPath."lib/xtpl.php";
include $rootPath."classes/db.php";
include $rootPath."classes/gui.php";
include $rootPath."classes/upload.php";
////////////////
$DB = new DBCLASS();
$GUI = new GUI();

////////////////

////////////////
if(isset($_GET['lang'])){
    if($_GET['lang']=='vn'){
        $_SESSION['ID_LANG'] = 1;
    }
    elseif($_GET['lang']=='en'){
        $_SESSION['ID_LANG'] = 2;
    }
}
if(!isset($_SESSION['ID_LANG']) || $_SESSION['ID_LANG']==0){
    $_SESSION['ID_LANG'] = 1;
}
if($_SESSION['ID_LANG']==1){
    include $rootPath."language/vn.php";
}
else{
    include $rootPath."language/en.php";
}
$sql="SELECT * FROM bm_config";
$rs=mysql_query($sql);
if(mysql_num_rows($rs)>0){
	$site_config=mysql_fetch_array($rs);
	$site_config['year']=date("Y");
	
}

$mod = "home";
$act = $_GET['act'];
$identify = $_GET['identify'];

if(strtolower(substr($_GET['detail_id'], 0, 1)) == 't'){
	$iPage = substr($_GET['detail_id'], 1);
}else{
	$detailID = $_GET['detail_id'];
}

if($act==''){
	$act = "index";
}

if($act== "index"){
    $xtpl_main = new XTemplate($templates."main.html");
    $xtpl_main->assign("kindPage","home");
    
}
else{
    $xtpl_main = new XTemplate($templates."main.html");
    $xtpl_main->assign("kindPage","innerpage");
}

$xtpl_main->assign($act."_active",'class="active"');
//--

$filename = "modules/{$mod}/{$act}.php";
//--
if(file_exists($filename)){
    
    $xtpl_main->assign("path_layout",$tem_layout);
    
	include $filename;
	@$xtpl_main->assign("site",$row_config);
	@$xtpl->assign("site",$row_config);
}else{
	include $base_url."modules/home/error.php";
}
/************
/************
/************
/************
/***********/

@$xtpl->parse("center");
$xtpl_main->assign("center_file",$xtpl->text("center"));
$xtpl_main->assign("path_site",$base_url);
$xtpl_main->assign("base_url",$base_url);
//--
/************
/************
/************  Donot change the above unless you know what you are doing
/************
/***********/

if($act=="listproduct"){
	$xtpl_main->assign("displayCat","block");
}
else{
	$xtpl_main->assign("displayCat","none");
}

$xtpl_main->assign("site",$site_config);
$xtpl_main->parse("MAIN");
eval("?".">".$xtpl_main->text("MAIN"));
logViewer();
function logViewer(){
	$ip=$_SERVER['REMOTE_ADDR'];
	$url_redirect =$_SERVER['HTTP_REFERER'];
	$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
	$sql = "INSERT DELAYED INTO bm_log (ip,url,url_redirect,activity,session,user_agent) value ".
		"('".$ip."','".$url."','".$url_redirect."','".date("Y-m-d H:i:s")."', '".session_id()."','".$_SERVER['HTTP_USER_AGENT']."')";

	mysql_query($sql);
}
?>
